#pragma once
#include <Windows.h>
#include <process.h>
#include "..\src\inc\zqm_app.h"

#define __HIGH_CODE

typedef struct {
    char *uart_port_str;            // 串口名称字串
    HANDLE mutex;
    HANDLE uart;                    // 串口句柄
    HANDLE pipe_read;               // 用管道模拟串口 pipe read handle
    HANDLE pipe_write;              // 用管道模拟串口 pipe write handle
    HANDLE rx_thread;               // 通讯接收线程句柄
    uint8_t* rx_buf;
    uint16_t rx_buf_size;
    volatile uint16_t rx_buf_pos;
} ZqSimuUartHandle;
extern ZqSimuUartHandle zq_simu_uart_handle[];

typedef struct {
    uint8_t key[3];
    uint16_t adc[4];      // 0-3：NTC1，NTC2，VBAT，VREF

    uint32_t gpioa;       // 值; 每个bit表示一个IO
    uint32_t gpiob;       // 值; 每个bit表示一个IO
    uint32_t gpioa_d;     // 输入/输出; 每个bit表示一个IO, 1 表示输出
    uint32_t gpiob_d;     // 输入/输出; 每个bit表示一个IO
    //uint32_t gpioa_pu;    // 上拉输入; 每个bit表示一个IO
    //uint32_t gpiob_pu;    // 上拉输入; 每个bit表示一个IO
    //uint32_t gpioa_pd;    // 下拉输入; 每个bit表示一个IO
    //uint32_t gpiob_pd;    // 下拉输入; 每个bit表示一个IO
} SimuHWData;


extern HANDLE simu_main_h;  // 主任务线程句柄
extern HANDLE simu_mutex;   // 主任务线程互斥, 用来模拟器采样和主任务线程隔离


extern SimuHWData simu_hw;         // 模拟硬件数据, 由模拟器周期下发

extern void TMOS_SystemProcess(void);

extern void DllPrintf(char* fmt, ...);
extern void EEPROM_READ(uint32_t StartAddr, uint8_t* Buffer, int Length);
extern void EEPROM_ERASE(uint32_t StartAddr, int Length);
extern void EEPROM_WRITE(uint32_t StartAddr, uint8_t* Buffer, int Length);
extern void FLASH_ROM_READ(uint32_t StartAddr, uint8_t* Buffer, int Length);
extern void FLASH_ROM_ERASE(uint32_t StartAddr, int Length);
extern void FLASH_ROM_WRITE(uint32_t StartAddr, uint8_t* Buffer, int Length);

extern void SimuBuzzor(int isOn);

extern void SimuUartInit(uint8_t port, int baudrate, uint8_t* rx_buf, uint16_t rx_buf_size);
extern void SimuUartClose(uint8_t port);
extern void SimuUartSend(uint8_t port, uint8_t* buf, uint16_t len);
//extern void SimuUartRecv(uint8_t port, void (*rx_cb)(ZqCommPkg* pkg));
//extern void SimuC485Recv(void (*rx_cb)(ZqCommPkg* pkg));
extern void RTC_InitTime(uint16_t y, uint16_t mon, uint16_t d, uint16_t h, uint16_t m, uint16_t s);
extern void RTC_GetTime(uint16_t* py, uint16_t* pmon, uint16_t* pd, uint16_t* ph, uint16_t* pm, uint16_t* ps);